//
//  SimInvader.cpp
//  Texture
//
//  Created by Yao Melo on 2/24/13.
//
//

#include "SimInvader.h"
SimInvader::SimInvader(Vec3 position)
{
    this->position = position;
    motionState = eMoveRight;
}

//the moving track:
//---------------------
//                    |
//---------------------
//|
//---------------------
void SimInvader::Update(float delta)
{
    float deltaDist = delta * INVADER_VELOCITY;
    movedDistance+= deltaDist;
    switch (motionState) {
        case eMoveLeft:
            position.x -= deltaDist;
            if(movedDistance>PlAYFEILD_X_MAX)
            {
                movedDistance = 0;
                motionState = eMoveDown;
                isLastMoveLeft = true;
            }
            break;
        case eMoveRight:
            position.x += deltaDist;
            if(movedDistance > PlAYFEILD_X_MAX)
            {
                movedDistance = 0;
                motionState = eMoveDown;
                isLastMoveLeft = false;
            }
            break;
        case eMoveDown:
            position.z += deltaDist;
            if(movedDistance > 1)
            {
                movedDistance=0;
                motionState = isLastMoveLeft?eMoveRight:eMoveLeft;
            }
            break;

    }
}